package com.hldsmart.smartda.adapter.home;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hldsmart.smartda.R;
import com.hldsmart.smartda.model.entity.TypesEntity;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;


/**
 * Created by lzh on 2017/1/16.
 * 平台服务类型适配器
 */

public class TypeAdapter extends RecyclerView.Adapter<TypeAdapter.ViewHolder> {


    private ArrayList<TypesEntity> types;

    public void setData(ArrayList<TypesEntity> types){
        this.types = types;

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_type_item,parent,false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

        holder.tv_shoptype.setText(types.get(position).getTypesname());
        holder.iv_type_image.setImageResource(types.get(position).getTypeimage());
        View.OnClickListener listener=new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(position);
            }
        };
        holder.ll_service_type.setOnClickListener(listener);
    }


    @Override
    public int getItemCount() {
        return types.size();
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView tv_shoptype;//服务类型
        public ImageView iv_type_image;//类型图片
        public LinearLayout ll_service_type;//类型图片

        public ViewHolder(View view){
            super(view);
            tv_shoptype = (TextView) view.findViewById(R.id.tv_service_type);
            iv_type_image = (ImageView) view.findViewById(R.id.iv_type_image);
            ll_service_type = (LinearLayout) view.findViewById(R.id.ll_service_type);

        }


    }

}
